package com.example.zx.theline.lyjh.pub;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.zx.theline.R;
import com.example.zx.theline.pub.CheckInfoActivity;

import java.util.ArrayList;
import java.util.List;

import GsonBean.LjyyxShdwFzrdh;
import Utils.MyToast;
import Utils.RefreshManager;
import Utils.StatusUtil;
import app.MyApplication;
import base.BaseActivity;
import dialog.ThDialog;

/**
 * 计划审核查看，只能用于查看 跟退回
 */
public class JhshCKActivity extends BaseActivity implements View.OnClickListener {
    public static GsonBean.ShyjhxqBean ZsyjhxxShBean;
    //标题
    private TextView centerTextView;
    //计划内容
    private TextView lb, yf, ydbh, kssj,  xm, dd, hb, lc, xmmc, sgnr, sgjx, blfh;
    // 相关单位
    private TextView sgdw, sgdwfzr, jldw, jldwfzr, jsdw, cwzd, sbgldw, qtdw, shcs, xmzgbm;
    // 按钮
    private TextView tv_cancel, tv_jhshth,tv_shliucheng;
    private TextView rightTextView, leftTextView;
    private LinearLayout button_layout, blfh_layout;

    private ThDialog mThDialog;
    //审核单位负责人
    List<LjyyxShdwFzrdh> shdwFzrList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jhsh_cha_kan);
        InitView();
        InitData();
        InitListen();
    }

    @Override
    protected void InitView() {



        lb = (TextView) findViewById(R.id.lb);
        yf = (TextView) findViewById(R.id.yf);
        ydbh = (TextView) findViewById(R.id.ydbh);
        kssj = (TextView) findViewById(R.id.kssj);
        xm = (TextView) findViewById(R.id.xm);
        dd = (TextView) findViewById(R.id.dd);
        hb = (TextView) findViewById(R.id.hb);
        lc = (TextView) findViewById(R.id.lc);
        xmmc = (TextView) findViewById(R.id.xmmc);
        sgnr = (TextView) findViewById(R.id.sgnr);
        sgjx = (TextView) findViewById(R.id.sgjx);
        blfh = (TextView) findViewById(R.id.blfh);

        sgdw = (TextView) findViewById(R.id.sgdw);
        sgdwfzr = (TextView) findViewById(R.id.sgdwfzr);
        jldw = (TextView) findViewById(R.id.jldw);
        jldwfzr = (TextView) findViewById(R.id.jldwfzr);
        jsdw = (TextView) findViewById(R.id.jsdw);
        cwzd = (TextView) findViewById(R.id.cwzd);
        sbgldw = (TextView) findViewById(R.id.sbgldw);
        qtdw = (TextView) findViewById(R.id.qtdw);
        shcs = (TextView) findViewById(R.id.shcs);
        xmzgbm = (TextView) findViewById(R.id.xmzgbm);
        tv_shliucheng = (TextView) findViewById(R.id.tv_shliucheng);

        tv_cancel = (TextView) findViewById(R.id.tv_cancel);

        tv_jhshth = (TextView) findViewById(R.id.tv_jhshth);
        button_layout = (LinearLayout) findViewById(R.id.button_layout);

        centerTextView = (TextView) findViewById(R.id.centerTextView);
        leftTextView = (TextView) findViewById(R.id.leftTextView);
        rightTextView = (TextView) findViewById(R.id.rightTextView);
        blfh_layout = (LinearLayout) findViewById(R.id.blfh_layout);

        centerTextView.setText("月计划详情");
        rightTextView.setVisibility(View.INVISIBLE);
    }


    @Override
    protected void InitData() {

        if (ZsyjhxxShBean == null) {
            MyApplication.ShowWaitDialog(this);
            MyApplication.setWaitDialogMsg("数据错误");
        } else {
            lb.setText(ZsyjhxxShBean.getInfo().getLb());
            yf.setText(ZsyjhxxShBean.getInfo().getSgny());
            ydbh.setText(ZsyjhxxShBean.getInfo().getBh());

            //施工日期
            kssj.setText(ZsyjhxxShBean.getInfo().getExsgrq());
            xm.setText(ZsyjhxxShBean.getInfo().getXlxbList().get(0).getXlmc());
            dd.setText(ZsyjhxxShBean.getInfo().getXlxbList().get(0).getSgdd());
            hb.setText(ZsyjhxxShBean.getInfo().getXlxbList().get(0).getXbmc());
            lc.setText(ZsyjhxxShBean.getInfo().getXlxbList().get(0).getLic());
            xmmc.setText(ZsyjhxxShBean.getInfo().getXmmc());
            sgnr.setText(ZsyjhxxShBean.getInfo().getNrmc());
            sgjx.setText(ZsyjhxxShBean.getInfo().getJxmc());
            //若类别为C类，则B类防护隐藏不显示
            if (ZsyjhxxShBean.getInfo().getLb().equals("C")) {
                blfh_layout.setVisibility(View.GONE);
            } else {
                blfh_layout.setVisibility(View.VISIBLE);
                blfh.setText(ZsyjhxxShBean.getInfo().getFhcsmc());
            }
            sgdw.setText(ZsyjhxxShBean.getInfo().getSgdwmc()); //施工单位名称
            sgdwfzr.setText(ZsyjhxxShBean.getInfo().getSgdwfzr());
            jldw.setText(ZsyjhxxShBean.getInfo().getJldw());
            jldwfzr.setText(ZsyjhxxShBean.getInfo().getJldwfzr());
            jsdw.setText(ZsyjhxxShBean.getInfo().getJsdwmc()); //建设单位名称
            cwzd.setText(ZsyjhxxShBean.getInfo().getCwzd());
            sbgldw.setText(ZsyjhxxShBean.getInfo().getSbgldw());
            qtdw.setText(ZsyjhxxShBean.getInfo().getQtdw());
            shcs.setText(ZsyjhxxShBean.getInfo().getShcsmc()); //审核处室名称
            xmzgbm.setText(ZsyjhxxShBean.getInfo().getSpcsmc()); //审批处室名称

            //根据月计划中yjhDwlb属性值是否=='spcs',则为项目主管部门进行审核，是可以退回到施工单位。
            //退回按钮显示 只有状态为待审核时，才显示退回按钮
            if (ZsyjhxxShBean.getInfo().getYjhDwlb() != null && ZsyjhxxShBean.getInfo().getYjhDwlb().equals("spcs")
                    && ZsyjhxxShBean.getInfo().getYjhCxValue().equals(StatusUtil.STATUS_YJH_DSH)) {
                tv_jhshth.setVisibility(View.VISIBLE);
            } else {
                tv_jhshth.setVisibility(View.GONE);
            }
        }


    }

    @Override
    protected void InitListen() {

        tv_cancel.setOnClickListener(this);
        leftTextView.setOnClickListener(this);
        tv_jhshth.setOnClickListener(this);
        tv_shliucheng.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //返回
            case R.id.leftTextView:
                finish();
                break;
            case R.id.tv_cancel:
                finish();
                break;
            //退回
            case R.id.tv_jhshth:
                mThDialog = new ThDialog(this, ThDialog.SHTH, ZsyjhxxShBean, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        MyToast.showToast("退回施工单位成功");
                        RefreshManager.Sgyjh.RefreshShyjh();
                        RefreshManager.Sgyjh.RefreshShywc();
                        JhshCKActivity.this.finish();
                        mThDialog.dismiss();
                    }
                });
                mThDialog.show();
                break;

            case R.id.tv_shliucheng:
                CheckInfoActivity.ZsyjhxxShBean = ZsyjhxxShBean;
                Intent intent = new Intent(this, CheckInfoActivity.class);
                startActivity(intent);
                break;

        }
    }

}
